using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RankPanel : BasePanel<RankPanel>
{
    public CustomGUIButton btnclose;
    private List<CustomGUILabel> labPlayerNames = new List<CustomGUILabel>();
    private List<CustomGUILabel> labScores = new List<CustomGUILabel>();
    private List<CustomGUILabel> labTimes = new List<CustomGUILabel>();
    void Start()
    {
        btnclose.clickEvent += () =>
        {
            BeginPanel.Instance.ShowMe();
            HideMe();
        };
        //得到对应组件，便于数据更新
        for (int i = 1; i <= 10; i++)
        {

            // var rank = transform.Find("Ranks/Rank " + i).GetComponent<CustomGUILabel>();
            // if (rank != null)
            //     labRanks.Add(rank);

            var playerName = transform.Find("PlayerNames/PlayerName " + i).GetComponent<CustomGUILabel>();
            if (playerName != null)
                labPlayerNames.Add(playerName);

            var score = transform.Find("Scores/Score " + i).GetComponent<CustomGUILabel>();
            if (score != null)
                labScores.Add(score);

            var time = transform.Find("Times/Time " + i).GetComponent<CustomGUILabel>();
            if (time != null)
                labTimes.Add(time);
        }
        // GameDataMgr.Instance.AddRankInfo(new RankInfo("测试数据", 100, 8432));
        HideMe();
    }
    public void updatePanelInfo()
    {
        List<RankInfo> list = GameDataMgr.Instance.rankData.list;
        for (int i = 0; i < list.Count; i++)
        {
            labPlayerNames[i].content.text = list[i].name;
            labScores[i].content.text = list[i].score.ToString();
            int time = (int)list[i].time;
            labTimes[i].content.text = "";
            if (time / 3600 > 0)
            {
                labTimes[i].content.text += time / 3600 + "时";
            }
            if (time % 3600 / 60 > 0 || time / 3600 > 0)
            {
                labTimes[i].content.text += time % 3600 / 60 + "分";
            }
            labTimes[i].content.text += time % 60 + "秒";
        }
    }
    public override void ShowMe()
    {
        base.ShowMe();
        updatePanelInfo();
    }
}
